package thread;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/4/27
 * Time:20:26
 * 线程状态
 **/
public class ThreadDemo16 {
    public static void main(String[] args) throws InterruptedException {

        /*//打印线程所有的状态
        for (Thread.State item : Thread.State.values()) {
            System.out.println(item);
        }*/

        Object obj = new Object();

        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (obj){
                    try {
                        obj.wait();//休眠线程
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                /*try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }*/
            }
        });
        System.out.println("start之前的状态" + t1.getState());
        t1.start();
        System.out.println("start之后的状态" + t1.getState());
        Thread.sleep(100);
        System.out.println("t1的状态"+t1.getState());
        //等待线程执行完成
        t1.join();
        /*while(!t1.isAlive()){

        }*/
        System.out.println("线程执行完成后的状态" + t1.getState());
    }
}
